#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],sum[maxn];
bool cmp(LL b,LL c){return b<c;}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;cin>>n;
  for(LL i=1;i<=n;i++) cin>>a[i];
  sort(a+1,a+1+n,cmp);
  if(n==1){
    cout<<"0"<<"\n";return 0;
  }
  for(LL i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
  LL ans=sum[n];
  if(n%3==0){
    for(LL i=1;i<=n;i++){
        if(i+2==n){
            ans+=a[i-2]+a[i-1];
            break;
        }
        else if(i%3==0){
            ans+=(sum[i]-sum[i-3]);
        }
    }
    cout<<ans<<"\n";
  }
  else if(n%2==0){
    for(LL i=1;i<=n;i++){
        if(i+2>n){
            break;
        }
        else if(i%2==0){
            ans+=(sum[i]-sum[i-2]);
        }
    }
    cout<<ans<<"\n";
  }
return 0;
}
